import * as serviceApi from '@/services/center';

// 默认查询条件
const defaultCond = {
  userId: null,
  isLock: 0,
  year: 0,
  month: 0,
  lockDateStart: null,
  lockDateEnd: null,
  pageNumber: 1,
  pageSize: 20,
};

export default {
  namespace: 'center',
  state: {
    data: [],
    qc: defaultCond,
    current: undefined,
  },

  effects: {
    *getMBLView({ payload, callback }, { call, put }) {
      const res = yield call(serviceApi.query, payload);
      if (callback) callback(res);
      yield put({
        type: 'save',
        payload: res,
      });
      yield put({
        type: 'saveQc',
        payload: payload,
      });
    },
    *reSetQC({ payload, callback }, { call, put }) {
      const res = yield call(serviceApi.query, defaultCond);
      yield put({
        type: 'save',
        payload: res,
      });
      yield put({
        type: 'saveQc',
        payload: defaultCond,
      });
      if (callback) callback(res);
    },
  },
  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload,
      };
    },
    saveQc(state, action) {
      return {
        ...state,
        qc: action.payload,
      };
    },
  },
};
